package com.itheima.message;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*
pom.xml
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>4.5.3</version>
</dependency>
*/
public class SendSmsaaa {
    public static final String VALIDATE_CODE = "SMS_205459063";//发送短信验证码
    public static final String ORDER_NOTICE = "SMS_205473788";//体检预约成功通知

    /**
     *  注册会员发送短信
     */
    public static void registerSendCode(String sendyourTelephoneNumber,String codeNumber)  {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GB2EZmi2Hs54ersSpwY", "L6L7MRMLf5CQrxRagzzbkUA5k08NEw");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", sendyourTelephoneNumber);
        request.putQueryParameter("SignName", "传智黑马115");
        request.putQueryParameter("TemplateCode", VALIDATE_CODE);
        request.putQueryParameter("TemplateParam",  "{\"code\":\""+codeNumber+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    /**
     * 预约成功 发送短信通知
     */

    public static void appointment_Is_Ok(String sendyourTelephoneNumber,String codeNumber)  {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GB2EZmi2Hs54ersSpwY", "L6L7MRMLf5CQrxRagzzbkUA5k08NEw");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", sendyourTelephoneNumber);
        request.putQueryParameter("SignName", "传智黑马115");
        request.putQueryParameter("TemplateCode", ORDER_NOTICE);
        request.putQueryParameter("TemplateParam",  "{\"code\":\""+codeNumber+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    //测试
    public static void main(String[] args) {
        appointment_Is_Ok("18737200256","666666");
    }
}
